$().ready( function() {
    
    jQuery.validator.addMethod( "validPassword", function(value) {
        var pass = $('#UserPassword').val();
        if(value != pass){
            return false;
        }       
        return true;
    }, 'Las contraseñas no coinciden');

    $("#UserAddForm").validate( {
        rules: {
            "data[User][name]": {
                required: true,
                rangelength: [3,45]
            },
            "data[User][enabled]": {
                required: true
            },
            "data[User][deleted]": {
                required: true
            },
            "data[User][password]": {
                required: true,
                rangelength: [3,45]
            },
            "data[User][password_repeat]": {
                required: true,
                rangelength: [3,45],
                validPassword: true
            }
        },
        messages: {
            "data[User][name]": {
                required: "<?php __('Ingrese el nombre') ?>",
                rangelength: "<?php __('Ingrese entre 3 y 45 caracteres') ?>"
            },
            "data[User][enabled]": {
                required: "<?php __('Seleccione') ?>"
            },
            "data[User][deleted]": {
                required: "<?php __('Seleccione') ?>"
            },
            "data[User][password]": {
                required: "<?php __('Ingrese la contraseña') ?>",
                rangelength: "<?php __('Ingrese entre 3 y 45 caracteres') ?>"
            },
            "data[User][password_repeat]": {
                required: "<?php __('Ingrese la contraseña') ?>",
                rangelength: "<?php __('Ingrese entre 3 y 45 caracteres') ?>"                
            }
        }

    } );
} );